#include <string.h>
#include "data.hpp"
uint8_t data_s::GET_L_BYTE(int index)
{	
	uint8_t ret_value=0;
	ret_value = uint8_t(data[index] & 0x0f);
	return ret_value;
}	
uint8_t data_s::GET_H_BYTE(int index)
{
	uint8_t ret_value=0;
	ret_value = uint8_t(data[index] & 0xf0);
	return ret_value;
}
uint8_t data_s::GET_1_BYTE(int index)
{
	uint8_t ret_value=0;
	ret_value = uint8_t(data[index]);
	return ret_value;
}
uint16_t data_s::GET_2_BYTE(int index)
{
	uint16_t ret_value=0;
	ret_value = uint16_t(
		((ret_value|uint16_t(data[index]))<<8)|
		((ret_value|uint16_t(data[index+1]))<<8)
		);
	return ret_value;
}
uint32_t data_s::GET_4_BYTE(int index)
{
	uint32_t ret_value=0;
	ret_value = uint32_t(
		((ret_value|uint32_t(data[index]))<<8)|
		((ret_value|uint32_t(data[index+1]))<<8)|
		((ret_value|uint32_t(data[index+2]))<<8)|
		((ret_value|uint32_t(data[index+3]))<<8)
		);
	return ret_value;
}
uint64_t data_s::GET_8_BYTE(int index)
{
	uint64_t ret_value=0;
	ret_value = uint64_t(
		((ret_value|uint64_t(data[index]))<<8)|
		((ret_value|uint64_t(data[index+1]))<<8)|
		((ret_value|uint64_t(data[index+2]))<<8)|
		((ret_value|uint64_t(data[index+3]))<<8)|
		((ret_value|uint64_t(data[index+4]))<<8)|
		((ret_value|uint64_t(data[index+5]))<<8)|
		((ret_value|uint64_t(data[index+6]))<<8)|
		((ret_value|uint64_t(data[index+7]))<<8)
		);
	return ret_value;
}
data_s::data_s(const uint8_t data[DATATCLASS_LENGTH])
{
	memcpy(this->data,data,sizeof(this->data));

	text.ctl = GET_H_BYTE(0);
	text.type = GET_L_BYTE(0);
	text.length_total = uint32_t(uint32_t(GET_2_BYTE(1)<<8)|uint32_t(GET_1_BYTE(3)));
	text.number = GET_2_BYTE(4);
	text.length_data = GET_2_BYTE(6);
	memcpy(text.data, data + 8, size_t(DATA_LENGTH));//
}
data_s::data_s(const text_t& text)
{
	this->text=text;

	data[0] = ((((uint8_t)0) |
		text.ctl) << 4) |
		text.type;
	data[1] = (text.length_total&(0xff0000)) >> 16;
	data[2] = (text.length_total&(0xff00)) >> 8;
	data[3] = (text.length_total&(0xff)) >> 0;
	data[4] = (text.number&(0xff00)) >> 8;
	data[5] = (text.number&(0xff)) >> 0;
	data[6] = (text.length_data&(0xff00)) >> 8;
	data[7] = (text.length_data&(0xff)) >> 0;
	memcpy(data + 8, text.data, 1472 - 8);
}